package com.fcscs.cservice.ws.endpoint;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ws.server.endpoint.annotation.Endpoint;
import org.springframework.ws.server.endpoint.annotation.PayloadRoot;
import org.springframework.ws.server.endpoint.annotation.RequestPayload;
import org.springframework.ws.server.endpoint.annotation.ResponsePayload;

import com.fcscs.cservice.ws.schema.common.MenuListView;
import com.fcscs.cservice.ws.schema.common.PictureFrameView;
import com.fcscs.cservice.ws.schema.common.PictureView;
import com.fcscs.cservice.ws.schema.mainmenuservice.MainMenuRequest;
import com.fcscs.cservice.ws.schema.mainmenuservice.MainMenuResponse;
import com.fcscs.cservice.ws.schema.mainmenuservice.MasterMainMenuRequest;
import com.fcscs.cservice.ws.schema.mainmenuservice.MasterMainMenuResponse;
import com.fcscs.ecms.service.ECMSMainMenuManager;

@Endpoint
public class MainMenuServiceEndpoint {
	@Autowired
	ECMSMainMenuManager mmMgr;
	
	
	@PayloadRoot(localPart = CServiceWSConstants.MAIN_MENU_ITEM_RQ, namespace = CServiceWSConstants.MAIN_MENU_SERVICE_NAMESPACE_URI)
	@ResponsePayload
	public MainMenuResponse mainMenuProgress(@RequestPayload MainMenuRequest req){
//		System.out.println("ok");
//		MainMenuResponse mainmemuResponse = new MainMenuResponse();
//		MenuListView menuListView = new MenuListView();
//		menuListView.setId(10);
//		menuListView.setTypeId("123");
//		menuListView.setSubtitle("asd");
//		menuListView.setTitle("asdasdas");
//		PictureFrameView pictureFrameView = new PictureFrameView();
//		pictureFrameView.setId(20l);
//		pictureFrameView.setPeriod(10l);
//		pictureFrameView.setVersion(20l);
//		ArrayList<PictureView> list = new ArrayList<PictureView>();
//		PictureView pic = new PictureView();
//		pic.setId(10l);
//		pic.setVersion(20l);
//		list.add(pic);
//		pictureFrameView.setPictureViewList(list);
//		menuListView.setPictureView(pic);
//		ArrayList<MenuListView> listMain = new ArrayList<MenuListView>();
//		listMain.add(menuListView);
//		mainmemuResponse.setMenuListViewList(listMain);
//		mainmemuResponse.setPictureFrameView(pictureFrameView);
//		System.out.println(mainmemuResponse);
//		return mainmemuResponse;
//		
//		mmMgr.getPictureFrameViews(req.getOrgId(),req.getPropId(),1);
		long propId = req.getPropId();
		long orgId = req.getOrgId();
		List<MenuListView> menuListView =  mmMgr.getMenuListViews(orgId,propId,"en_us");
		PictureFrameView pictureFrameView = mmMgr.getPictureFrameViews(orgId, propId,1);
//		PictureFrameView pictureFrameView = mmMgr.getPictureFrameViews(req.getOrgId(), req.getPropId());
		
//		PictureFrameView pictureFrameView = new PictureFrameView();
//		pictureFrameView.setId(20l);
//		pictureFrameView.setPeriod(10l);
//		pictureFrameView.setVersion(20l);
//		ArrayList<PictureView> list = new ArrayList<PictureView>();
//		PictureView pic = new PictureView();
//		pic.setId(10l);
//		pic.setVersion(20l);
//		list.add(pic);
//		pictureFrameView.setPictureViewList(list);
		MainMenuResponse mainMenuResponse = new MainMenuResponse();
		mainMenuResponse.setMenuListViewList(menuListView);
		mainMenuResponse.setPictureFrameView(pictureFrameView);
//		System.out.println(menuListView.size()+" ");
//		System.out.println(menuListView.get(1).getSubtitle());
//		System.ou t.println(menuListView.get(0).getSubtitle());
	return mainMenuResponse ;
	}
	@PayloadRoot(localPart = CServiceWSConstants.MAIN_MENU_MASTER_ITEM_RQ, namespace = CServiceWSConstants.MAIN_MENU_SERVICE_NAMESPACE_URI)
	@ResponsePayload
	public MasterMainMenuResponse mainMenuProgress(@RequestPayload MasterMainMenuRequest req){
//		System.out.println("ok");
//		MainMenuResponse mainmemuResponse = new MainMenuResponse();
//		MenuListView menuListView = new MenuListView();
//		menuListView.setId(10);
//		menuListView.setTypeId("123");
//		menuListView.setSubtitle("asd");
//		menuListView.setTitle("asdasdas");
//		PictureFrameView pictureFrameView = new PictureFrameView();
//		pictureFrameView.setId(20l);
//		pictureFrameView.setPeriod(10l);
//		pictureFrameView.setVersion(20l);
//		ArrayList<PictureView> list = new ArrayList<PictureView>();
//		PictureView pic = new PictureView();
//		pic.setId(10l);
//		pic.setVersion(20l);
//		list.add(pic);
//		pictureFrameView.setPictureViewList(list);
//		menuListView.setPictureView(pic);
//		ArrayList<MenuListView> listMain = new ArrayList<MenuListView>();
//		listMain.add(menuListView);
//		mainmemuResponse.setMenuListViewList(listMain);
//		mainmemuResponse.setPictureFrameView(pictureFrameView);
//		System.out.println(mainmemuResponse);
//		return mainmemuResponse;
//		
//		mmMgr.getPictureFrameViews(req.getOrgId(),req.getPropId(),1);
		long propId = req.getPropId();
		long orgId = req.getOrgId();
		List<MenuListView> menuListView =  mmMgr.getMasterMenuListViews(orgId,propId,"en_us");
		PictureFrameView pictureFrameView = mmMgr.getPictureFrameViews(orgId, propId,0);
//		PictureFrameView pictureFrameView = mmMgr.getPictureFrameViews(req.getOrgId(), req.getPropId());
		
//		PictureFrameView pictureFrameView = new PictureFrameView();
//		pictureFrameView.setId(20l);
//		pictureFrameView.setPeriod(10l);
//		pictureFrameView.setVersion(20l);
//		ArrayList<PictureView> list = new ArrayList<PictureView>();
//		PictureView pic = new PictureView();
//		pic.setId(10l);
//		pic.setVersion(20l);
//		list.add(pic);
//		pictureFrameView.setPictureViewList(list);
		MasterMainMenuResponse mainMenuResponse = new MasterMainMenuResponse();
		mainMenuResponse.setMenuListViewList(menuListView);
		mainMenuResponse.setPictureFrameView(pictureFrameView);
//		System.out.println(menuListView.size()+" ");
//		System.out.println(menuListView.get(1).getSubtitle());
//		System.out.println(menuListView.get(0).getSubtitle());
	return mainMenuResponse ;
	}
}
